package com.shixi.shixitraining.shixitraining.ui.tabapply.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.shixi.shixitraining.shixitraining.R;
import com.shixi.shixitraining.shixitraining.base.BaseActivity;
import com.shixi.shixitraining.shixitraining.http.CallbackImple;
import com.shixi.shixitraining.shixitraining.http.HttpUtil;
import com.shixi.shixitraining.shixitraining.ui.tabapply.entity.EmploymentDetailBean;
import com.shixi.shixitraining.shixitraining.util.ToastUtil;
import com.shixi.shixitraining.shixitraining.util.UserManager;

import butterknife.ButterKnife;
import retrofit2.Call;

import static com.shixi.shixitraining.shixitraining.constant.Constants.APPLYEMPLOYMENTDETAIL;

public class EmploymenApplyDetailActivity extends BaseActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_employmen_apply_detail);
        ButterKnife.bind(this);
        initTitle();
        Intent intent = getIntent();
        if (intent != null) {
            Bundle bundle = intent.getExtras();
            String number = bundle.getString("number");
            requestEmployDetail(number);
        }
    }

    private void requestEmployDetail(String number) {

        String token = UserManager.getInstance().getToken();
        String userId = UserManager.getInstance().getUserId();
        String url = APPLYEMPLOYMENTDETAIL +"&userId="+ userId +"&token="+token +"&number="+number;
        HttpUtil.getInstance().getApiInterface().applyEmploymentDetail(url).enqueue(new CallbackImple<EmploymentDetailBean>() {
            @Override
            public void onError(Call<EmploymentDetailBean> call, Throwable t) {
                ToastUtil.showShortToast(EmploymenApplyDetailActivity.this, t.getMessage());
            }

            @Override
            public void onSuccess(Call<EmploymentDetailBean> call, EmploymentDetailBean response) {
                if (response.getData() != null) {
                    if (response.getStatus() == 200) {
                        EmploymentDetailBean.DataBean data = response.getData();
                        String address = data.getAddress();
                        String addtime = data.getAddtime();
                        String deposit = data.getDeposit();
                        String nature = data.getNature();
                        String title = data.getTitle();
                        String steps = data.getSteps();
                        String stepsCn = data.getStepsCn();
                        String trade = data.getTrade();
                        String status = data.getStatus();

                        TextView mEmploymentTitle = (TextView) findViewById(R.id.apply_employ_title_tv);
                        TextView mCity = (TextView) findViewById(R.id.apply_employ_city_tv);
                        TextView mNature = (TextView) findViewById(R.id.traing_offical_tv);
                        TextView mTime = (TextView) findViewById(R.id.apply_employ_time_tv);
                        TextView mSteps = (TextView) findViewById(R.id.commit_list_success);
                        TextView mStepsCn = (TextView) findViewById(R.id.tv_apply_des);
                        mEmploymentTitle.setText(title.toString());
                        mCity.setText(address.toString());
                        mNature.setText(nature.toString());
                        mTime.setText(addtime.toString());
                        mSteps.setText(steps.toString());
                        mStepsCn.setText(stepsCn);

                    } else {
                        ToastUtil.showShortToast(EmploymenApplyDetailActivity.this, response.getMsg());
                    }

                } else {
                    ToastUtil.showShortToast(EmploymenApplyDetailActivity.this, "数据为空");
                }

            }
        });

    }

    private void initTitle() {
        ImageView mBackImg = (ImageView) findViewById(R.id.iv_back);
        mBackImg.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                this.finish();
                break;
        }
    }
}
